package com.example.crm.controller.api;

import com.example.crm.entity.Region;
import com.example.crm.vo.Result;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * 通用API控制器
 */
@RestController
@RequestMapping("/api/common")
public class CommonAPIController {

    /**
     * 获取区域列表
     */
    @GetMapping("/regions")
    public Result<List<Map<String, Object>>> getRegions() {
        try {
            // 模拟区域数据
            List<Map<String, Object>> regions = new ArrayList<>();
            
            // 华东区
            Map<String, Object> huadong = new HashMap<>();
            huadong.put("id", 1);
            huadong.put("name", "华东区");
            huadong.put("code", "HD");
            huadong.put("parentId", null);
            regions.add(huadong);
            
            // 华北区
            Map<String, Object> huabei = new HashMap<>();
            huabei.put("id", 2);
            huabei.put("name", "华北区");
            huabei.put("code", "HB");
            huabei.put("parentId", null);
            regions.add(huabei);
            
            // 华南区
            Map<String, Object> huanan = new HashMap<>();
            huanan.put("id", 3);
            huanan.put("name", "华南区");
            huanan.put("code", "HN");
            huanan.put("parentId", null);
            regions.add(huanan);
            
            // 上海
            Map<String, Object> shanghai = new HashMap<>();
            shanghai.put("id", 4);
            shanghai.put("name", "上海");
            shanghai.put("code", "SH");
            shanghai.put("parentId", 1);
            regions.add(shanghai);
            
            // 北京
            Map<String, Object> beijing = new HashMap<>();
            beijing.put("id", 5);
            beijing.put("name", "北京");
            beijing.put("code", "BJ");
            beijing.put("parentId", 2);
            regions.add(beijing);
            
            // 广州
            Map<String, Object> guangzhou = new HashMap<>();
            guangzhou.put("id", 6);
            guangzhou.put("name", "广州");
            guangzhou.put("code", "GZ");
            guangzhou.put("parentId", 3);
            regions.add(guangzhou);
            
            return Result.success(regions);
        } catch (Exception e) {
            return Result.error("获取区域列表失败: " + e.getMessage());
        }
    }
    
    /**
     * 获取系统选项
     */
    @GetMapping("/options/{type}")
    public Result<List<Map<String, Object>>> getOptions(@PathVariable String type) {
        try {
            List<Map<String, Object>> options = new ArrayList<>();
            
            // 根据类型返回不同的选项
            switch (type) {
                case "role":
                    // 角色选项
                    Map<String, Object> leader = new HashMap<>();
                    leader.put("value", "leader");
                    leader.put("label", "团队领导");
                    options.add(leader);
                    
                    Map<String, Object> manager = new HashMap<>();
                    manager.put("value", "manager");
                    manager.put("label", "销售经理");
                    options.add(manager);
                    
                    Map<String, Object> rep = new HashMap<>();
                    rep.put("value", "representative");
                    rep.put("label", "销售代表");
                    options.add(rep);
                    break;
                    
                case "industry":
                    // 行业选项
                    String[] industries = {"IT/互联网", "金融/保险", "教育/培训", "医疗/健康", "制造业", "零售/消费", "房地产/建筑", "其他"};
                    for (int i = 0; i < industries.length; i++) {
                        Map<String, Object> industry = new HashMap<>();
                        industry.put("value", "ind_" + (i + 1));
                        industry.put("label", industries[i]);
                        options.add(industry);
                    }
                    break;
                    
                case "source":
                    // 来源选项
                    String[] sources = {"网站", "搜索引擎", "社交媒体", "邮件营销", "电话营销", "合作伙伴", "客户推荐", "展会/活动", "其他"};
                    for (int i = 0; i < sources.length; i++) {
                        Map<String, Object> source = new HashMap<>();
                        source.put("value", "src_" + (i + 1));
                        source.put("label", sources[i]);
                        options.add(source);
                    }
                    break;
                    
                default:
                    return Result.error("不支持的选项类型: " + type);
            }
            
            return Result.success(options);
        } catch (Exception e) {
            return Result.error("获取选项列表失败: " + e.getMessage());
        }
    }
} 